package breadbox.dataManagement;
import java.util.Hashtable;
import java.util.TreeSet;

import breadbox.pastry.ID;

public class MemStorage implements Storage {
		
	private Hashtable<ID, byte[]> data;
	
	public MemStorage() {
		
		data = new Hashtable<ID, byte[]>();
		
	}
	
	public boolean exists(ID id) {
		return data.containsKey(id);
	}
	
	public byte[] get(ID id)  {
		if(data.containsKey(id)) {
			return data.get(id);
		}
		return null;
	}
	
	public int write(ID id, byte[] d) {
		if(data.containsKey(id)) {
			System.out.println("writeFragments: already contains fragment " + id);
			return 1;
		}
		data.put(id, d);
		
		return 0;
	}
	public void delete(ID id) {
		data.remove(id);
	}
	
	//memstorage will probably not be used anymore
	//no need to implement
	public TreeSet<Long> allChunks() {
		return null;
	}
	
	public void deleteIfOld(ID id, long l) {
		return;
	}
	
	//data in memory doesn't have a timestamp
	public void touch(ID i) {
		return;
	}
}